// 例4-2 fcntl修改文件描述符属性
/*fcntltest.c*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
    int flags;
    int append_flag; 
    int nonblock_flag;
    int access_mode;
    int file_descriptor; 
    char *text1="abcdefghij";
    char *text2="0123456789";
    char read_buffer[25];
    memset(read_buffer,'\0',25);
    file_descriptor = creat("testfile",S_IRWXU);
    write(file_descriptor,text1,10);
    close(file_descriptor);
    file_descriptor = open("testfile",O_RDWR);
    read(file_descriptor,read_buffer,24); 
    printf("first read is \'%s\'\n", read_buffer);
    lseek(file_descriptor,0,SEEK_SET);
    fcntl(file_descriptor,F_SETFL,O_APPEND);
    write(file_descriptor,text2,10); 
    lseek(file_descriptor,0,SEEK_SET);
    read(file_descriptor,read_buffer,24);
    printf("second read is \'%s\'\n", read_buffer);
    close(file_descriptor); 
    unlink("testfile");
    return 0;
}

